<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
            <el-form-item label="摄影师姓名" prop="cameramanName">
                <el-input v-model="queryParams.cameramanName" placeholder="请输入摄影师姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                    v-hasPermi="['ski:note:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['ski:note:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="noteList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="真实姓名" align="center" prop="cameramanName" width="150" show-overflow-tooltip />
            <el-table-column label="联系方式" align="center" prop="phone" width="120" show-overflow-tooltip />
            <el-table-column label="性别" align="center" prop="sex" width="120">
                <template slot-scope="scope">
                    <img style="width:25px;" v-if="scope.row.sex == 0" src="../../../assets/images/woman.png" alt="">
                    <img style="width:25px;" v-if="scope.row.sex == 1" src="../../../assets/images/man.png" alt="">
                </template>
            </el-table-column>
            <el-table-column label="身份证号" align="center" prop="cameramanIdCard" show-overflow-tooltip />
            <el-table-column label="主运营城市" align="center" prop="operateCityCode">
                <template slot-scope="scope">
                    <span v-for="item in province" :key="item.id" v-if="item.id == scope.row.operateCityCode">
                        {{ item.name }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="滑雪技能" align="center" prop="skiSkill">
                <template slot-scope="scope">
                    <el-tag size="small" type="warning" v-if="scope.row.skiSkill == 'single_board'">单板</el-tag>
                    <el-tag size="small" type="warning" v-if="scope.row.skiSkill == 'double_board'">双板</el-tag>
                    <el-tag size="small" type="success" v-if="scope.row.skiSkill == 'metropolitan'">都会</el-tag>
                    <el-tag size="small" type="info"
                        v-if="scope.row.skiSkill == 'none' || !scope.row.skiSkill">什么都不会</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="常驻雪场名称" align="center" prop="snowFieldId" show-overflow-tooltip>
                <template slot-scope="scope">
                    <span v-for="ele in scope.row.snowFieldId.split(',')" :key="ele">
                        <span v-for="item in snowFieldName" :key="item.id" v-if="item.id == ele">
                            {{ item.snowField }},
                        </span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="审核状态" align="center" prop="auditStatus">
                <template slot-scope="scope">
                    <el-tag type="success" size="small" v-if="scope.row.auditStatus == 'agree'">通过</el-tag>
                    <el-tag type="warning" size="small" v-if="scope.row.auditStatus == 'apply'">申请中</el-tag>
                    <el-tag type="info" size="small" v-if="scope.row.auditStatus == 'refund'">拒绝</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="审核员备注" align="center" prop="auditorRemarks" show-overflow-tooltip />
            <el-table-column label="申请时间" align="center" prop="createTime" show-overflow-tooltip />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.auditStatus == 'apply'"
                        @click="handleAudit(scope.row)">审核</el-button>
                    <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)">详情</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <!-- 添加或修改套餐配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
            <el-form ref="form" :model="form" label-width="110px">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="真实姓名" prop="cameramanName">
                            {{ form.cameramanName }}
                        </el-form-item>
                        <el-form-item label="性别" prop="sex">
                            <img style="width:25px;" v-if="form.sex == 0" src="../../../assets/images/woman.png">
                            <img style="width:25px;" v-if="form.sex == 1" src="../../../assets/images/man.png">
                        </el-form-item>
                        <el-form-item label="主营城市" prop="province">
                            <span v-for="item in province" :key="item.id" v-if="form.operateCityCode == item.id">
                                {{ item.name }}
                            </span>
                        </el-form-item>
                        <el-form-item label="滑雪技能" prop="skiSkill">
                            <el-tag type="warning" v-if="form.skiSkill == 'single_board'">单板</el-tag>
                            <el-tag type="warning" v-if="form.skiSkill == 'double_board'">双板</el-tag>
                            <el-tag type="success" v-if="form.skiSkill == 'metropolitan'">都会</el-tag>
                            <el-tag type="info" v-if="form.skiSkill == 'none' || !form.skiSkill">什么都不会</el-tag>
                        </el-form-item>
                        <el-form-item label="身份证正面照" prop="handIdFrontImage">
                            <img style="width:120px;" :src="form.handIdFrontImage">
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="联系方式" prop="phone">
                            {{ form.phone }}
                        </el-form-item>
                        <el-form-item label="身份证号" prop="cameramanIdCard">
                            {{ form.cameramanIdCard }}
                        </el-form-item>
                        <el-form-item label="主营雪场">
                            <span v-for="ele in snowFieldIds" :key="ele">
                                <span v-for="item in snowFieldName" :key="item.id" v-if="item.id == ele">
                                    {{ item.snowField }},
                                </span>
                            </span>
                        </el-form-item>
                        <el-form-item label="审核状态" prop="auditStatus">
                            <el-tag type="success" v-if="form.auditStatus == 'agree'">通过</el-tag>
                            <el-tag type="warning" v-if="form.auditStatus == 'apply'">申请中</el-tag>
                            <el-tag type="info" v-if="form.auditStatus == 'refund'">拒绝</el-tag>
                        </el-form-item>
                        <el-form-item label="身份证反面照" prop="handIdOppositeImage">
                            <img style="width:120px;" :src="form.handIdOppositeImage">
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { noteList, detailSkill, deleteSkill, auditSkill, AllCounty } from "@/api/business/skill";
import { listInfo } from '@/api/business/info'

export default {
    name: "Meal",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 摄影师申请列表
            noteList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                cameramanName: null,
            },
            // 表单参数
            form: {},
            //主营城市
            province: [],
            //主营雪场
            snowFieldName: [],
            //主营雪场ids
            snowFieldIds: []
        };
    },
    created() {
        this.getList();
        this.getAllCounty();
        this.getSkillList();
    },
    methods: {
        /** 查询套餐配置列表 */
        getList() {
            this.loading = true;
            noteList(this.queryParams).then(response => {
                this.noteList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 获取地区数据
        getAllCounty() {
            AllCounty(0).then(res => {
                this.province = res.data
            })
        },
        // 获取雪场数据
        getSkillList() {
            listInfo().then(res => {
                listInfo().then(res => {
                    this.snowFieldName = res.rows
                })
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /**详情按钮操作 */
        handleDetail(row) {
            const id = row.id || this.ids
            detailSkill(id).then(response => {
                this.form = response.data;
                this.snowFieldIds = this.form.snowFieldId.split(',')
                this.open = true;
                this.title = '摄影师详情';
            });
        },
        /** 审核按钮操作 */
        handleAudit(row) {
            this.$confirm('是否审核通过该摄影师？', '提示', {
                distinguishCancelAndClose: true,
                confirmButtonText: '通过',
                cancelButtonText: '拒绝',
                type: 'warning'
            }).then(() => {
                auditSkill({
                    noteId: row.id,
                    auditStatus: "agree"
                }).then(() => {
                    this.$message({
                        type: 'success',
                        message: '已通过该摄影师注册!'
                    });
                    this.getList()
                })
            }).catch((action) => {
                if (action == 'cancel') {
                    this.$prompt('请输入拒绝理由', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                    }).then(({ value }) => {
                        auditSkill({
                            noteId: row.id,
                            auditStatus: "refund",
                            auditorRemarks: value
                        }).then(res => {
                            this.$message({
                                type: 'info',
                                message: '拒绝理由: ' + value
                            });
                            this.getList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '取消拒绝'
                        });
                    });
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除套餐配置编号为"' + ids + '"的数据项？').then(function () {
                return deleteSkill(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('system/note/export', {
                ...this.queryParams
            }, `note_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
<style></style>
